package com.study.mcp;

import io.modelcontextprotocol.client.McpClient;
import io.modelcontextprotocol.client.transport.ServerParameters;
import io.modelcontextprotocol.client.transport.StdioClientTransport;
import io.modelcontextprotocol.spec.McpSchema;

import java.util.Map;

public class ClientStdio {

	public static void main(String[] args) {

		var stdioParams = ServerParameters.builder("java")
			.args("-jar",
					"mcp-server-stdio/target/mcp-server-stdio-0.0.1-SNAPSHOT.jar")
			.build();

		var transport = new StdioClientTransport(stdioParams);
		var client = McpClient.sync(transport).build();

		client.initialize();

		// List and demonstrate tools
		McpSchema.ListToolsResult toolsList = client.listTools();
		System.out.println("Available Tools = " + toolsList);

		McpSchema.CallToolResult weatherForcastResult = client.callTool(new McpSchema.CallToolRequest("getWeatherForecastByLocation",
				Map.of("latitude", "40.206", "longitude", "116.165")));
		System.out.println("Weather Forcast: " + weatherForcastResult);

		client.closeGracefully();
	}

}